﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using WorkStation.Frameworks.Core;
using WorkStation.Frameworks.Core.Extensions;
using WorkStation.Frameworks.EasyBus.Extensions;

namespace WorkStation.Frameworks.EasyBus.Configurations
{
    public static class IBusExtensions
    {
        public static IBus SetFileConfigProvider(this IBus bus, string configKey) 
        {
            IConfigProvider provider = new FileConfigProvider(configKey) { Bus = bus };

            bus.SetConfigProvider(provider);

            return bus;
        }

        /// <summary>
        /// 设置 Bus 的文件配置，以 EasyBus.{ busName }.{ nodeName } 为 Key 。
        /// </summary>
        /// <param name="bus"></param>
        /// <returns></returns>
        public static IBus SetFileConfigProvider(this IBus bus) 
        {
            string configKey = "EasyBus.{0}.{1}".Fmt(bus.Name, bus.NodeName);

            return bus.SetFileConfigProvider(configKey);
        }
    }
}
